package com.aspose.cells;

class zgz implements zafw {
   private int a;
   private short b;
   private Cells c;
   private zahl d;
   private zahl e;
   private RowCollection f;
   private zr g;
   private zp h;
   private LightCellsDataProvider i;
   private zall j;
   private zaln k;
   private zalm l;
   private zbbj m;
   private zbbj n;
   private Row o;
   private Row p;
   private int q;
   private int r;
   private int s;
   private int t;
   private int u;
   private int v;
   private int w = -1;
   private int x = -1;
   private zalh y;
   private int z;
   private boolean A;
   private boolean B;

   zgz(Worksheet var1, LightCellsDataProvider var2, zalh var3) {
      this.a = var3.c.a;
      this.b = var3.c.b;
      this.c = var1.getCells();
      this.f = this.c.getRows();
      this.i = var2;
      this.y = var3;
      this.g = this.c.f();
      this.k = new zaln(this.c, this.f, var3);
      this.j = (zall)this.k.a;
      this.n = this.j.a;
      this.m = new zbbj();
      this.m.a(0, this.c);
      this.l = new zalm(this.k, var3, 0, this.j.l());
      this.d = this.g.a(-1, -1, false);
      this.s = this.d.a();
      if (this.s > -1) {
         this.o = this.f.b(this.s, false);
         this.u = this.o.getIndex();
      } else {
         this.u = -1;
      }

   }

   public zaln a() {
      return this.A ? this.k : null;
   }

   public zalm b() {
      return this.B ? this.l : null;
   }

   public zp c() {
      int var1 = this.i.nextRow();
      if (var1 >= 0 && var1 <= this.a) {
         if (var1 <= this.w) {
            throw new CellsException(6, "Row index must be greater than prior one.");
         } else {
            this.w = var1;
            this.q = -1;
            if (this.u > -1) {
               if (var1 > this.u) {
                  do {
                     this.s = this.d.a();
                     if (this.s < 0) {
                        this.u = -1;
                        break;
                     }

                     this.o = this.f.b(this.s, false);
                     this.u = this.o.getIndex();
                  } while(this.u < var1);
               }

               if (var1 == this.u) {
                  this.q = this.s;
                  this.p = this.o;
                  this.h = this.p.a;
                  this.s = this.d.a();
                  if (this.s > -1) {
                     this.o = this.f.b(this.s, false);
                     this.u = this.o.getIndex();
                  } else {
                     this.u = -1;
                  }

                  this.e = this.h.a(-1, -1, false);
                  if (this.e == null) {
                     this.t = -1;
                     this.v = -1;
                  } else {
                     this.t = this.e.a();
                     this.v = this.t < 0 ? -1 : this.h.a(this.t);
                  }

                  this.A = false;
                  this.x = -1;
                  this.z = -1;
                  this.i.startRow(this.p);
                  return this.h;
               }
            }

            this.v = -1;
            this.m.a = var1;
            this.j.b(this.m, 15);
            this.A = true;
            this.x = -1;
            this.z = -1;
            this.i.startRow(this.k);
            return this.k.a;
         }
      } else {
         return null;
      }
   }

   public zfv d() {
      int var1 = this.i.nextCell();
      if (var1 >= 0 && var1 <= this.b) {
         if (var1 <= this.x) {
            throw new CellsException(6, "Cell's column index must be greater than prior one.");
         } else {
            this.x = var1;
            if (this.v > -1) {
               if (var1 > this.v) {
                  do {
                     this.t = this.e.a();
                     if (this.t < 0) {
                        this.v = -1;
                        break;
                     }

                     this.v = this.p.a.a(this.t);
                  } while(this.v < var1);
               }

               if (this.v == var1) {
                  this.r = this.t;
                  Cell var2 = this.p.a(this.t);
                  this.t = this.e.a();
                  this.v = this.t < 0 ? -1 : this.h.a(this.t);
                  this.B = false;
                  this.i.startCell(var2);
                  return var2.c;
               }
            }

            this.r = 0;
            this.B = true;
            this.l.c(var1);
            if (this.z < 0) {
               if (this.A) {
                  this.z = this.k.d();
               } else {
                  this.z = this.y.b(this.p.d());
               }
            }

            this.j.k(this.z);
            this.i.startCell(this.l);
            return this.l.c;
         }
      } else {
         return null;
      }
   }
}
